package com.tianji.learning.controller;

import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.query.QuestionAdminPageQuery;
import com.tianji.learning.domain.vo.QuestionAdminVO;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/questions")
@Api(tags = "互动问答相关接口")
@RequiredArgsConstructor
public class InteractionQuestionAdminController {
    private final IInteractionQuestionService interactionQuestionService;

    /**
     * 管理端问题分页查询
     *
     * @param query
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "管理端问题分页查询")
    public PageDTO<QuestionAdminVO> queryAdminQuestionsPage(QuestionAdminPageQuery query) {
        return interactionQuestionService.queryAdminQuestionsPage(query);
    }

    /**
     * 管理员修改问题是否可见
     *
     * @param id
     * @param hidden
     */
    @PutMapping("/{id}/hidden/{hidden}")
    @ApiOperation(value = "管理员修改问题是否可见")
    public void updateQuestionHiddenById(@ApiParam(name = "问题id") @PathVariable(value = "id") Long id,
                                         @ApiParam(name = "是否隐藏") @PathVariable(value = "hidden") Boolean hidden) {
        interactionQuestionService.updateQuestionHiddenById(id, hidden);
    }

    /**
     * 管理端通过问题id查看问题详情
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "管理端通过问题id查看问题详情")
    public QuestionAdminVO adminGetQuestionById(@ApiParam(name = "问题id")
                                                @PathVariable(value = "id") Long id) {
        return interactionQuestionService.adminGetQuestionById(id);
    }
}
